<template>
	<view class="person_password">
		<view class="main">
			<!-- <view class="input">
				<view class="left">登录密码</view>
				<view class="right">
					<u-input v-model="old_pass" type="password" :clearable='false' placeholder='请输入登录密码' />
				</view>
			</view> -->
			<view class="input">
				<view class="left">用户ID</view>
				<view class="right">
					<u-input v-model="phone" type="number" :clearable='false' placeholder='请输入ID' />
				</view>
			</view>
			<!-- <view class="input">
				<view class="left">验证码</view>
				<view class="right_code">
					<u-input v-model="code" type="number" :clearable='false' placeholder='请输入验证码' />
					<text @click="sendCodeBtn">{{codeTxt}}</text>
				</view>
			</view> -->
		</view>
		<!-- 底部 -->
		<BottomBtn title='保存' @submit='submitBtn'></BottomBtn>
	</view>
</template>

<script>
	import BottomBtn from '@/components/bottom_btn/bottom_btn.vue';
	export default {
		components:{
			BottomBtn
		},
		data() {
			return {
				old_pass:'',
				phone:'',
				code:'',
				//
				disabled:false,
				codeTxt:'发送验证码',
				sendTime:60,
				time:null,
			};
		},
		methods:{
			// 发送验证码
			sendCodeBtn(){
				var that = this
				if(that.disabled){
					return
				}
				if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
					that.$tips.showToast('请输入正确的手机号')
					return
				}else{
					that.$tips.showLoading('发送中')
					var params = {
						mobile:that.phone,
						event:'changemobile'
					}
					that.$httpApi.smsSend(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							if (!that.timer) {
							  that.disabled = true
							  that.codeTxt = that.sendTime+'s'
							  that.timer = setInterval(() => {
							    if (that.sendTime > 0 && that.sendTime <= 60) {
							      that.sendTime--
							      that.codeTxt = that.sendTime+'s'
							    } else {
							      that.disabled = false
							      that.sendTime = 60
							      that.codeTxt = '重新获取'
							      clearInterval(that.timer)
							      that.timer = null;
							    }
							  }, 1000)
							}
						}
					})
				}
			},
			// 底部按钮
			submitBtn(){
				var that = this
				if(that.old_pass==''){
					that.$tips.showToast('请输入登录密码')
					return
				}else if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
					that.$tips.showToast('请输入正确的手机号')
					return
				}else if(that.code==''){
					that.$tips.showToast('请输入验证码')
					return
				}else{
					that.$tips.showLoading('修改中')
					var params = {
						password:that.old_pass,
						mobile:that.phone,
						captcha:that.code
					}
					that.$httpApi.userChangemobile(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							that.$tips.showToast('修改成功')
							that.$store.dispatch('GetUserInfo')
							setTimeout(function(){
								uni.navigateBack()
							},2000)
						}
					})
				}
			},
		}
	}
</script>

<style lang="less">
	.person_password{
		width: 100%;
		padding-top: 24rpx;
		.main{
			width: 100%;
			padding: 20rpx 32rpx;
			background: #fff;
			.input{
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				.left{
					width: 200rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}
				.right{
					width: calc(100% - 200rpx);
					display: flex;
					align-items: center;
					u-input{
						width: 100%;
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
				.right_code{
					width: calc(100% - 200rpx);
					display: flex;
					align-items: center;
					justify-content: space-between;
					u-input{
						width: calc(100% - 160rpx);
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
					text{
						display: block;
						width: 160rpx;
						line-height: 70rpx;
						text-align: center;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #26C281;
					}
				}
			}
		}
	}
</style>
